package leetcode.array;

import javax.print.DocFlavor;

/**
 * @program: java_learning
 * @description
 * @author: 辛旭初
 * @create: 2020-09-16 14:30
 **/
public class Question66 {

    static public int[] plusOne(int[] digits) {

        StringBuilder stringBuilder = new StringBuilder();
        for (int item:digits
             ) {
            stringBuilder.append(item);
        }
        String result = Math.round(Double.parseDouble(stringBuilder.toString()))+"";
        String[] strings = new String[result.length()];
        for (int i = 0; i < result.length(); i++) {
            strings[i] = result.charAt(i)+"";
        }


        int[] ans = new int[strings.length];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = Integer.parseInt(strings[i]);
        }

        return ans;
    }

    /**
     * 这里要要解决两个问题
     * 一个是9的进一引起的变化
     * 二是进一引起的数字位数加一（这个之前确实是没有想到）
     * @param digits
     * @return
     */
    static public int[] plusOne1(int[] digits) {

        for (int i = digits.length - 1; i >= 0; i--) {
            digits[i]++;
            digits[i] = digits[i] % 10;
            if (digits[i] != 0){return digits;}
        }
        digits = new int[digits.length + 1];
        digits[0] = 1;
        return digits;
    }

    public static void main(String[] args) {

        int[] ans = plusOne1(new int[]{9,8,7,6,5,4,3,2,1,0});
        for (int i = 0; i < ans.length; i++) {
            System.out.println(ans[i]);
        }
    }
}
